package com.sinovate.liteEMS.app1.web.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {

	@RequestMapping("/hello")
	public String hello() {
		return "success";
	}

	@RequestMapping(value = "/attr", method = RequestMethod.POST)
	public String setAttr(@RequestParam("key") String key,
			@RequestParam("value") String value) {
		SecurityUtils.getSubject().getSession().setAttribute(key, value);
		return "success";
	}

	@RequestMapping(value = "/attr", method = RequestMethod.GET)
	public String getAttr(@RequestParam("key") String key, Model model) {
		model.addAttribute("value", SecurityUtils.getSubject().getSession()
				.getAttribute(key));
		return "success";
	}

	@RequestMapping("/role1")
	@RequiresRoles("role1")
	public String role1() {
		return "success";
	}

}
